package com.zivwu.library.ui.base;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.trello.rxlifecycle2.components.RxFragment;
import com.zivwu.library.utils.ToastUtil;


public abstract class IFragment extends RxFragment {
    protected Context mContext;
    protected ViewGroup mRootView;


    @TargetApi(Build.VERSION_CODES.M)
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.mContext = context;

    }


    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        this.mContext = activity;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle arguments = getArguments();
        if (arguments != null) {
            initArguments(arguments);
        }
    }

    protected void initArguments(Bundle arguments) {

    }



    /**
     * 进行一个toast提示
     *
     * @param msg 需要显示的MESSAGE
     */
    public void showToast(String msg) {
        ToastUtil.showToast(mContext.getApplicationContext(), msg);
    }

    public void showToast(@StringRes int id) {
        showToast(this.getString(id));
    }


    @Override
    public void onDetach() {
        super.onDetach();
        this.mContext = null;
        this.mRootView = null;
    }
}
